package com.jf.mall.dao.impl;

import com.jf.mall.dao.BasicDAO;
import com.jf.mall.dao.OrderDAO;
import com.jf.mall.domain.Order;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-10-10
 * Time:20:41
 */
public class OrderImpl extends BasicDAO<Order> implements OrderDAO {
    @Override
    public int insertOrder(Order order) {
        String sql = "insert into `order` values(?,?,?,?,?)";
        String id = order.getId();
        Integer userId = order.getUserId();
        BigDecimal amount = order.getAmount();
        Date orderTime = order.getOrderTime();
        Short state = order.getState();
        try {
            return update(sql, id, userId, amount, orderTime, state);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<Order> queryOrder(int userId) {
        String sql = "select id, user_id userId, amount, order_time orderTime, state from `order` where user_id = ?";
        return queryMulti(sql, Order.class, userId);
    }
}
